package top.kaoshanji.ch02;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;

/**
 * author kaoshanji
 * ^_^
 * create time 2024/11/16 11:20
 */
public class HelloComponent2 extends JComponent implements MouseMotionListener {

    String theMessage;
    int messageX = 125, messageY = 95;

    public HelloComponent2(String theMessage) {
        this.theMessage = theMessage;
        addMouseMotionListener(this);
    }

    @Override
    protected void paintComponent(Graphics g) {
        g.drawString(theMessage, messageX, messageY);
    }

    @Override
    public void mouseDragged(MouseEvent e) {
        messageX = e.getX();
        messageY = e.getY();
        repaint();
    }

    @Override
    public void mouseMoved(MouseEvent e) {

    }
}
